<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var array=[5,9,8,7,4,6,1,2];
        alert("原数组为："+array);
        console.log("原数组为："+array)
        function ascending(a){
            var i,j,t;
            var len=array.length;
	        for(i=0;i<len-1;i++)
	        {
    	        for(j=0;j<len-i-1;j++)
    	        {
			        if(a[j]>a[j+1])
			        {
        		        t=a[j+1];
        		        a[j+1]=a[j];
        		        a[j]=t;
    		        }
		        }
	        }
            console.log("升序排列后的数组为："+a);
            alert("升序排列后的数组为："+a);
        }
    </script>
    <style>
        div{
            text-align: center;
        }
    </style>
</head>
<body>
    <div><button onclick="ascending(array)">升序排列</button></div>
</body>
</html>